import java.util.Calendar;

public class Water {
    private int temperature;
    private boolean hasWater;
    private boolean isWorking;
    private boolean isBroken;
    private boolean isSleeping;

    public void WaterHeater() {
        temperature = 20;
        hasWater = true;
        isWorking = false;
        isBroken = false;
        isSleeping = false;
    }
    public void start() {
        while (true) {
            if (isSleeping) {
                System.out.println("Water heater is sleeping...");
                if (isMorning()) {
                    isSleeping = false;
                    System.out.println("Water heater wakes up!");
                }
            } else {
                if (temperature < 20) {
                    if (hasWater) {
                        isWorking = true;
                        System.out.println("Water heater starts working...");
                    } else {
                        System.out.println("No water in the water heater!");
                    }
                } else if (temperature >= 20 && temperature < 100) {
                    if (isWorking) {
                        temperature++;
                        System.out.println("Water temperature is " + temperature + " degrees.");
                    }
                } else if (temperature >= 100) {
                    isWorking = false;
                    System.out.println("Water heater stops working...");
                }

                if (isBroken) {
                    System.out.println("Water heater is broken!");
                    break;
                }

                if (isNight()) {
                    isSleeping = true;
                    System.out.println("Water heater goes to sleep...");
                }
            }
        }
    }

    public void setTemperature(int temperature) {
        this.temperature = temperature;
    }

    public void setHasWater(boolean hasWater) {
        this.hasWater = hasWater;
    }

    public void setIsBroken(boolean isBroken) {
        this.isBroken = isBroken;
    }

    private boolean isMorning() {
        Calendar calendar = Calendar.getInstance();
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        return hour == 7;
    }

    private boolean isNight() {
        Calendar calendar = Calendar.getInstance();
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        return hour == 23;
    }
}
